const app = getApp()
const publics = require('../../../../utils/public.js');
const md5 = require('../../../../utils/md5.js');
const http = require('../../../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      longitude:'',
      latitude:'',
      startingUpTime: '',
      payMoney: '',
      unit: '',
      payType: '',
      address: '',
      duration: '',
      img: '',
      orderId:'',
      markers:[],
      mapControls: [{   //地图中心
          id: 0,
          position: {                 //相对定位
              left: app.globalData.scWidth * 0.47,
              top: app.globalData.scHeight * 0.39,
              width: app.globalData.scHeight * 0.032,
              height:app.globalData.scHeight * 0.05
              
          },
          iconPath: "/images/d0.png",
          width: 30,
          height: 20,
          clickable: false
      }, {
          id: 1,
          position: {                 //相对定位
              left: app.globalData.scWidth * 0.00,
              top: app.globalData.scHeight * 0.38,
              width: app.globalData.scWidth * 0.15,
              height: app.globalData.scHeight * 0.091
          },
          iconPath: "/images/dw.png",          //相对于当前文件的路径
          clickable: true
      }
      ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.mapCtx = wx.createMapContext("myMap")
      this.mapCtx.moveToLocation()
      console.log(options)
      var orderId = options.orderId
      if (startingUpTime){
          var startingUpTime = options.startingUpTime
          this.setData({
              startingUpTime: startingUpTime,            
          })
      }
     
      this.setData({      
        orderId: orderId
      })
      var token = wx.getStorageSync('token')
      var data = {
        method: 'Order.info',
        token: token,
        orderId: orderId
      }
      var arr = http.sorts(data)
      var that = this
      data.sign = md5.hex_md5(arr)
      http._post(data, res => { 
        // console.log(res)
        var that = this
        var payMoney = that.data.payMoney
        var unit = that.data.unit
        var payType = that.data.payType
        var address = that.data.address
        var duration = that.data.address
        var img = that.data.img
        payMoney = res.data.data.orderInfo.payInfo.payMoney
        unit = res.data.data.orderInfo.payInfo.unit
        payType = res.data.data.orderInfo.payInfo.payType
        address = res.data.data.orderInfo.address
        duration = res.data.data.orderInfo.duration
        img = res.data.data.headPortrait
        that.setData({
          payMoney: payMoney,
          unit: unit,
          payType: payType,
          address: address,
          duration: duration,
          img: img
        })
      })
  },
  regionchange(e) {
      /** 中心点的位置 **/
      if (e.type == "end") {
          var that = this;
          console.log(that);
          this.mapCtx.getCenterLocation({
              success: (res) => {
                  console.log(res.latitude);
                  console.log(res.longitude);
              }
          })
      }
  },
  mapControlTap(e){
   
    switch (e.controlId){
        case 1:
            this.mapCtx.moveToLocation() 
        break;
    }
  },
  clickraise(){
    var token = wx.getStorageSync('token')
    var orderId = this.data.orderId
    var data = {
      method: 'Order.payment',
      token: token,
      orderId: orderId
    }
    var arr = http.sorts(data)
    data.sign = md5.hex_md5(arr)
    // console.log(arr)
    http._post(data, res => {
       console.log(res) 
       if(res.data.code==0){
           wx.reLaunch({
               url: '/pages/index/lymap/lymap',
           })
       }else{
           wx.showToast({
               title: res.data.msg,
               icon:'none',
               duration:1000
           })
       }
     
    })    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      let _this = this;
      wx.getLocation({
          type: 'gcj02',
          success: (res) => {
              _this.setData({
                  latitude: res.latitude,
                  longitude: res.longitude,
                  markers: [{
                      id: "1",
                      latitude: res.latitude - 0.001,
                      longitude: res.longitude,
                      iconPath: '/images/d1.png',
                      width: 30,
                      height: 32,
                      callout: {
                          content: "地址",
                          bgColor: "#ffffff",
                          color: "#ff0000",
                          padding: 10,
                          borderRadius: 5,
                          display: 'BYCLICK'
                      }
                  }, {
                      id: "2",
                      latitude: res.latitude + 0.0007,
                      longitude: res.longitude,
                      iconPath: '/images/d1.png',
                      width: 30,
                      height: 32,
                      callout: {
                          content: "地址",
                          bgColor: "#ffffff",
                          color: "#ff0000",
                          padding: 10,                   
                          borderRadius: 5,
                          display: 'BYCLICK'
                      }
                  }, {
                      id: "3",
                      latitude: res.latitude,
                      longitude: res.longitude - 0.001,
                      iconPath: '/images/d1.png',
                      width: 30,
                      height: 32,
                      callout: {
                          content: "华星时代广场",
                          bgColor: "#ffffff",
                          color: "#999",
                          padding: 10,
                          display: "ALWAYS",
                          borderRadius: 20,
                         
                      }
                  }

                  ]
              })

          }
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})